<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="UTF-8">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/static/"/>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="/static/css/pagination.css"/>
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        .tree-closed {
            height: 40px;
        }

        .tree-expanded {
            height: auto;
        }
    </style>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <div><a class="navbar-brand" style="font-size:32px;" href="#">众筹平台 - 控制面板</a></div>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li style="padding-top:8px;">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default btn-success dropdown-toggle"
                                data-toggle="dropdown">
                            <i class="glyphicon glyphicon-user"></i>${sessionScope['LOGIN-ADMIN'].loginacct}<span
                                class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#"><i class="glyphicon glyphicon-cog"></i> 个人设置</a></li>
                            <li><a href="#"><i class="glyphicon glyphicon-comment"></i> 消息</a></li>
                            <li class="divider"></li>
                            <li><a href="/admin/logout"><i class="glyphicon glyphicon-off"></i> 退出系统</a></li>
                        </ul>
                    </div>
                </li>
                <li style="margin-left:10px;padding-top:8px;">
                    <button type="button" class="btn btn-default btn-danger">
                        <span class="glyphicon glyphicon-question-sign"></span> 帮助
                    </button>
                </li>
            </ul>
            <form class="navbar-form navbar-right">
                <input type="text" class="form-control" placeholder="查询">
            </form>
        </div>
    </div>
</nav>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <div class="tree">
                <ul style="padding-left:0px;" class="list-group">
                    <li class="list-group-item tree-closed">
                        <a href="main.html"><i class="glyphicon glyphicon-dashboard"></i> 控制面板</a>
                    </li>
                    <li class="list-group-item tree-closed">
                        <span><i class="glyphicon glyphicon glyphicon-tasks"></i> 权限管理 <span class="badge"
                                                                                             style="float:right">3</span></span>
                        <ul style="margin-top:10px;display:none;">
                            <li style="height:30px;">
                                <a href="/admin/query/for/search"><i class="glyphicon glyphicon-user"></i> 用户维护</a>
                            </li>
                            <li style="height:30px;">
                                <a href="role.html"><i class="glyphicon glyphicon-king"></i> 角色维护</a>
                            </li>
                            <li style="height:30px;">
                                <a href="permission.html"><i class="glyphicon glyphicon-lock"></i> 许可维护</a>
                            </li>
                        </ul>
                    </li>
                    <li class="list-group-item tree-closed">
                        <span><i class="glyphicon glyphicon-ok"></i> 业务审核 <span class="badge"
                                                                                style="float:right">3</span></span>
                        <ul style="margin-top:10px;display:none;">
                            <li style="height:30px;">
                                <a href="auth_cert.html"><i class="glyphicon glyphicon-check"></i> 实名认证审核</a>
                            </li>
                            <li style="height:30px;">
                                <a href="auth_adv.html"><i class="glyphicon glyphicon-check"></i> 广告审核</a>
                            </li>
                            <li style="height:30px;">
                                <a href="auth_project.html"><i class="glyphicon glyphicon-check"></i> 项目审核</a>
                            </li>
                        </ul>
                    </li>
                    <li class="list-group-item tree-closed">
                        <span><i class="glyphicon glyphicon-th-large"></i> 业务管理 <span class="badge" style="float:right">7</span></span>
                        <ul style="margin-top:10px;display:none;">
                            <li style="height:30px;">
                                <a href="cert.html"><i class="glyphicon glyphicon-picture"></i> 资质维护</a>
                            </li>
                            <li style="height:30px;">
                                <a href="type.html"><i class="glyphicon glyphicon-equalizer"></i> 分类管理</a>
                            </li>
                            <li style="height:30px;">
                                <a href="process.html"><i class="glyphicon glyphicon-random"></i> 流程管理</a>
                            </li>
                            <li style="height:30px;">
                                <a href="advertisement.html"><i class="glyphicon glyphicon-hdd"></i> 广告管理</a>
                            </li>
                            <li style="height:30px;">
                                <a href="message.html"><i class="glyphicon glyphicon-comment"></i> 消息模板</a>
                            </li>
                            <li style="height:30px;">
                                <a href="project_type.html"><i class="glyphicon glyphicon-list"></i> 项目分类</a>
                            </li>
                            <li style="height:30px;">
                                <a href="tag.html"><i class="glyphicon glyphicon-tags"></i> 项目标签</a>
                            </li>
                        </ul>
                    </li>
                    <li class="list-group-item tree-closed">
                        <a href="param.html"><i class="glyphicon glyphicon-list-alt"></i> 参数管理</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <h1 class="page-header">控制面板</h1>

            <div class="row placeholders">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                    </div>
                    <div class="panel-body">
                        <form action="/admin/query/for/search.html" class="form-inline" role="form" style="float: left;"
                              method="post">
                            <div class="form-group has-feedback">
                                <div class="input-group">
                                    <div class="input-group-addon">查询条件</div>
                                    <input
                                            value="${param.keyword}"
                                            name="keyword"
                                            class="form-control has-success"
                                            type="text"
                                            placeholder="请输入查询条件">
                                </div>
                            </div>
                            <button type="submit" class="btn btn-warning">
                                <i class="glyphicon glyphicon-search"></i> 查询
                            </button>
                        </form>
                        <button id="batchRemoveBtn" type="button" class="btn btn-danger"
                                style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除
                        </button>
                        <a href="/admin/to/add/page.html" class="btn btn-primary" style="float: right;">
                            <i class="glyphicon glyphicon-plus"></i> 新增
                        </a>
                        <br>
                        <hr style="clear:both;">
                        <div class="table-responsive">
                            <table class="table  table-bordered">
                                <thead>
                                <tr>
                                    <th width="30">#</th>
                                    <th width="30"><input id="summaryBox" type="checkbox"></th>
                                    <th>账号</th>
                                    <th>名称</th>
                                    <th>邮箱地址</th>
                                    <th width="100">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:if test="${empty requestScope['PAGE-INFO'].list}">
                                    <tr>
                                        <td style="text-align: center;" colspan="6">抱歉！没有符合您要求的查询结果！</td>
                                    </tr>
                                </c:if>
                                <c:if test="${!empty requestScope['PAGE-INFO'].list}">
                                    <c:forEach items="${requestScope['PAGE-INFO'].list}" var="admin"
                                               varStatus="myStatus">
                                        <tr>
                                            <td>${myStatus.count}</td>
                                            <td><input adminId="${admin.id}" class="itemBox" type="checkbox"></td>
                                            <td>${admin.loginacct}</td>
                                            <td>${admin.username}</td>
                                            <td>${admin.email}</td>
                                            <td>
                                                <button type="button" class="btn btn-success btn-xs"><i
                                                        class=" glyphicon glyphicon-check"></i></button>
                                                <a href="/admin/to/edit/page?adminId=${admin.id }&pageNum=${requestScope['PAGE-INFO'].pageNum}" class="btn btn-primary btn-xs">
                                                    <i class=" glyphicon glyphicon-pencil"></i>
                                                </a>
                                                <button adminId="${admin.id}" type="button"
                                                        class="btn btn-danger btn-xs uniqueRemoveBtn"><i
                                                        class=" glyphicon glyphicon-remove"></i></button>

                                            </td>
                                        </tr>

                                    </c:forEach>
                                </c:if>
                                </tbody>

                                <tfoot>
                                <tr>
                                    <td colspan="6" align="center">
                                        <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                                    </td>
                                </tr>

                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="jquery/jquery-2.1.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="script/docs.min.js"></script>
<script type="text/javascript" src="script/jquery.pagination.js"></script>
<script src="layer/layer.js"></script>
<script type="text/javascript">

    $(".thumbnail img").css("cursor","pointer");
    $(".thumbnail img").click(function () {
        window.location.href="project.html";
    });

    $(function () {
        layer.msg("测试结果")
    })



    $(function () {
        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        $(function () {
            // 对分页导航条显示进行初始化
            initPagination();
        });

// 声明函数封装导航条初始化操作
        function initPagination() {
            // 声明变量存储总记录数
            var totalRecord = ${requestScope['PAGE-INFO'].total};
            // 声明变量存储分页导航条显示时的属性设置
            var paginationProperties = {
                num_edge_entries: 3,        //边缘页数
                num_display_entries: 5,      //主体页数
                callback: pageselectCallback, //回调函数
                items_per_page: ${requestScope['PAGE-INFO'].pageSize},    //每页显示数据数量，就是pageSize
                current_page: ${requestScope['PAGE-INFO'].pageNum - 1},//当前页页码
                prev_text: "上一页",       //上一页文本
                next_text: "下一页"        //下一页文本
            };
            // 显示分页导航条
            $("#Pagination").pagination(totalRecord, paginationProperties);
        }

// 在每一次点击“上一页”、“下一页”、“页码”时执行这个函数跳转页面
        function pageselectCallback(pageIndex, jq) {
            // pageIndex从0开始，pageNum从1开始
            var pageNum = pageIndex + 1;
            // 跳转页面
            window.location.href = "/admin/query/for/search?pageNum=" + pageNum + "&keyword=${param.keyword}";
            return false;
        }

        //（删除）批量标记
        $("#summaryBox").click(function () {
            // 获取当前#summaryBox的勾选状态
            // this代表当前多选框对象（DOM对象）
            // checked属性为true时表示被勾选，为false时表示没有被勾选
            // 使用checkStatus设置.itemBox的状态
            $(".itemBox").prop("checked", this.checked);
        });

        //删除
        $("#batchRemoveBtn").click(function () {
            // 创建数组对象：存储adminId
            var adminIdArray = new Array();
            // 创建数组对象：存储loginAcct
            var loginAcctArray = new Array();
            $(".itemBox:checked").each(function () {
                var adminId = $(this).attr("adminId");
                adminIdArray.push(adminId);
                var loginAcct = $(this).parent("td").next().text();
                loginAcctArray.push(loginAcct);

            });
            alert(adminIdArray)

            if (adminIdArray.length == 0) {
                alert("请勾选您要删除的记录！");
                return;
            }
            var confirmResult = confirm("您真的要删除" + loginAcctArray + "信息吗？操作不可逆，请谨慎决定！");
            if (confirmResult == false) {
                return;
            }
            var requestBody = JSON.stringify(adminIdArray);

            $.ajax({
                url: "/admin/batch/remove.json",
                "type": "post",
                "data": requestBody,
                "dataType": "json",
                "contentType": "application/json;charset=UTF-8",
                "success": function (response) {
                    var result = response.result;
                    if (result == "SUCCESS") {
                        // 跳转页面
                        window.location.href = "/admin/query/for/search.html?pageNum=${requestScope['PAGE-INFO'].pageNum}&keyword=${param.keyword}";
                    } else {
                        alert(response.message);
                        return;
                    }
                }
            });
        });


        //单条删除
        $(".uniqueRemoveBtn").click(function () {
            // 获取当前adminId值
            var adminId = $(this).attr("adminId");
            var loginAcct = $(this).parents("tr").children("td:eq(2)").text();
            var confirmResult = confirm("您真的要删除" + loginAcct + "这条记录吗？");

            if (!confirmResult) {
                return;
            }

            // 为了能够使用批量删除的操作，将adminId存入数组
            var adminIdArray = new Array();

            adminIdArray.push(adminId);

            // 调用专门封装的函数，执行批量删除
            doBatchRemove(adminIdArray);
        });

        function doBatchRemove(adminIdArray) {
            var requestBody = JSON.stringify(adminIdArray);

            $.ajax({
                url:"/admin/batch/remove.json",
                "type":"post",
                "data":requestBody,
                "dataType":"json",
                "contentType":"application/json;charset=UTF-8",
                "success":function(response){
                    var result = response.result;
                    if (result=="SUCCESS"){
                        // 跳转页面
                        window.location.href = "/admin/query/for/search.html?pageNum=${requestScope['PAGE-INFO'].pageNum}&keyword=${param.keyword}";
                    }else{
                        alert(response.message);
                        return ;
                    }
                }
            });
        }
    });
</script>
</body>
</html>
